/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import fever.display.cursor.AbstractCursor;
import fever.display.FilterBuilder;

import flash.filters.DropShadowFilter;

/**
 * Busy cursor ala Flex style.
 * 
 * <p>Example
 * {@code
 *   CursorManager.showCursor( CursorManager.add( new FlexBusyCursor(), 'BUSY' ) );
 * }
 * 
 * @author Romain Ecarnot @ MairieBureau
 */
class fever.display.cursor.FlexBusyCursor extends AbstractCursor
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _m : MovieClip;
	private var _h : MovieClip;
	
		
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */ 
	public function FlexBusyCursor() 
	{
		super( true );
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
	
	private function _paint() : Void
	{
		_m = _mcTarget.createEmptyMovieClip( '__m__', 2 );
		_h = _mcTarget.createEmptyMovieClip( '__h__', 3 );
		
		_drawBackGroundCircle();
		
		_m.clear();
		_m.lineStyle( 1, 0x68808c, 100 );
		_m.moveTo( 0, 0 );
		_m.lineTo( 0, -6 );
		
		_h.clear();
		_h.lineStyle( 1, 0x68808c, 100 );
		_h.moveTo( 0, 0 );
		_h.lineTo( 0, -9 );
		
		FilterBuilder.setShadow( _mcTarget, new DropShadowFilter( 1, 45, 0x000000, 0.4, 4, 4, 1, 2 ) );
	}
	
	private function _repaint(  ) : Void 
	{
		super._repaint();
		
		_m._rotation += 24;
		_h._rotation += 1;
	}
	
	/**
	 * Circle drawing algo is the AsWing AS2 Version
	 */
	private function _drawBackGroundCircle(  ) : Void 
	{
		var size : Number = 18;
		var x : Number = -9; 		var y : Number = -9; 
		
		var pi : Number = Math.PI;
        var xradius : Number = size / 2;
        var yradius : Number = size / 2;
        var cx : Number = x + xradius;
        var cy : Number = y + yradius;
        var tanpi8 : Number = Math.tan( pi / 8 );
        var cospi4 : Number = Math.cos( pi / 4 );
        var sinpi4 : Number = Math.sin( pi / 4 );
        
        _mcTarget.clear( );
        _mcTarget.beginFill(  0xffffff, 100  );
        _mcTarget.lineStyle(  1, 0x68808c, 100  );
        
        _mcTarget.moveTo( xradius + cx, 0 + cy );
        _mcTarget.curveTo( xradius + cx, ( yradius * tanpi8 ) + cy, ( xradius * cospi4 ) + cx, ( yradius * sinpi4 ) + cy );
        _mcTarget.curveTo( ( xradius * tanpi8 ) + cx, yradius + cy, 0 + cx, yradius + cy );
        _mcTarget.curveTo( ( ( -xradius ) * tanpi8 ) + cx, yradius + cy, ( ( -xradius ) * cospi4 ) + cx, ( yradius * sinpi4 ) + cy );
        _mcTarget.curveTo( ( -xradius ) + cx, ( yradius * tanpi8 ) + cy, ( -xradius ) + cx, 0 + cy );
        _mcTarget.curveTo( ( -xradius ) + cx, ( ( -yradius ) * tanpi8 ) + cy, ( ( -xradius ) * cospi4 ) + cx, ( ( -yradius ) * sinpi4 ) + cy );
        _mcTarget.curveTo( ( ( -xradius ) * tanpi8 ) + cx, ( -yradius ) + cy, 0 + cx, ( -yradius ) + cy );
        _mcTarget.curveTo( ( xradius * tanpi8 ) + cx, ( -yradius ) + cy, ( xradius * cospi4 ) + cx, ( ( -yradius ) * sinpi4 ) + cy );
        _mcTarget.curveTo( xradius + cx, ( ( -yradius ) * tanpi8 ) + cy, xradius + cx, 0 + cy );
        
        _mcTarget.endFill( );
	}

}